package my2Cents.tools;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;

import my2Cents.Sandbox;
import my2Cents.properties.CheckBox;
import net.phys2d.math.Vector2f;
import net.phys2d.raw.Body;
import net.phys2d.raw.shapes.PBox;
import net.phys2d.raw.shapes.PhysShape;

public abstract class AbstractBodyMaker extends AbstractPhysTool {	
	protected PhysShape shape;
	protected Vector2f shapePos = new Vector2f();
	protected float shapeAngle = 0.0f;
	protected BasicStroke stroke;
	protected boolean createStatic = false;
	
//	public AbstractBodyMaker(char key, Sandbox demo) {
//		super(key, demo);
//		setGhostColor(AbstractPhysTool.GHOSTCOLOR_CREATE);
//	}
	
	public AbstractBodyMaker() {
		category = "Primitives";
		setGhostColor(AbstractPhysTool.GHOSTCOLOR_CREATE);
		addProperty(new CheckBox("Static (Frozen)",false) {
			private static final long serialVersionUID = 1L;
			public void valueChanged(boolean b) {
				createStatic = b;
			}
		});
	}
	
	public boolean canDraw() {
		return (shape != null && inUse);
	}

	public GeneralPath getGhostPath() {
		if(shapePos != null && shape != null) {
			Vector2f pos = new Vector2f(shapePos);
			if(shape.getGeneralPath(pos,shapeAngle) != null) {
				return shape.getGeneralPath(pos,shapeAngle);
			}
		}
		return new GeneralPath();
	}
	
	public void startTool(MouseEvent arg0) {
		super.startTool(arg0);
		shapePos.x = arg0.getX();
		shapePos.y = arg0.getY();
		//Sandbox.translateToCameraSpace(shapePos);
	}
	
	public void endTool(MouseEvent arg0) {
		super.endTool(arg0);
		shape = new PBox(1,1);
	}
	
	public Body createBody(float mass) {
		Body b = this.sandbox.createBody(shape,mass,createStatic);
		return b;
	}

}
